import os

class AMethod:
	def __init__(self):
		self.a = ''

	def FootPrintChains(self, TrackArray):
		start = []
		start.append(TrackArray[0])
		for t in range(1, len(TrackArray)):
			for tmpindex in range(len(start)):
				if TrackArray[t][0] == start[tmpindex][-1]:
					start[tmpindex].append(TrackArray[t][-1])
					break
				elif TrackArray[t][0] in start[tmpindex][1:-1]:
					middleindex = start[tmpindex].index(TrackArray[t][0])
					newelement = start[tmpindex][:middleindex+1]
					newelement.append(TrackArray[t][-1])
					start.append(newelement)
					break
			else:
				start.append(TrackArray[t])
		return start
